<template>
    <div class="filter">
        <a-select @change="handleChange($event,0)" placeholder="职业证书" :value="defaultProfession">
            <a-select-option 
                :value="item.id" 
                v-for="(item,index) in professionList" 
                :key="index">
                {{item.name}}
            </a-select-option>
        </a-select>
        <a-select @change="handleChange($event,1)" placeholder="技能等级" :value="defaultSkill">
            <a-select-option 
                :value="item.id" 
                v-for="(item,index) in skillList" 
                :key="index">
                {{item.name}}
            </a-select-option>
        </a-select>
        <a-select @change="handleChange($event,2)" placeholder="考试类型" :value="defaultPaper">
            <a-select-option 
                :value="item.id" 
                v-for="(item,index) in paperTypeList" 
                :key="index">
                {{item.name}}
            </a-select-option>
        </a-select>
    </div>
</template>
<script>
import {getProfessionListApi,getSkillListApi} from "@/request/api"
export default {
    name:'examType',
    props:{defaultExamType:Array},
    created(){
        
        this.init()
    },
    data(){
        return{
            professionList:[],
            skillList:[],
            paperTypeList:[{name:'理论考试',id:0},{name:"实操考试",id:1},{name:'理论+实操',id:2}],
            arr:[],
            defaultProfession:undefined,
            defaultSkill:undefined,
            defaultPaper:undefined
        }
    },
    methods:{
        init(){
            this.getToken(getProfessionListApi,{},res=>{
                this.professionList=res.data
                this.getToken(getSkillListApi,{},res=>{
                    this.skillList=res.data
                    if(this.defaultExamType){
                        this.defaultProfession=this.defaultExamType[0]
                        this.defaultSkill=this.defaultExamType[1]
                        this.defaultPaper=this.defaultExamType[2]
                    }
                })
            })
        },
        handleChange(data,type){
            this.arr[type]=data
            if(type==0){
                this.defaultProfession=data
            }else if(type==1){
                this.defaultSkill=data
            }else{
                this.defaultPaper=data
            }
            this.$emit('changeExamType',this.arr)
        }
    }
}
</script>
<style lang="stylus" scoped>
.filter{
    display:flex;
    justify-content: space-between;
}
</style>